//
//  RHLocalChoiceEndpointCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/7/24.
//

#import "RHLocalChoiceEndpointCell.h"
#import "RHLocalEndpointModel.h"

@interface RHLocalChoiceEndpointCell()
@property (nonatomic ,strong) QMUILabel *devNameLab;

@property (nonatomic ,strong) QMUILabel *devIdLab;

@property (nonatomic ,strong) QMUILabel *devStateLab;

@property (nonatomic ,strong) UIImageView *markView;

@property (nonatomic ,strong) UIView *pointView;

@end
@implementation RHLocalChoiceEndpointCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    
    kWeakSelf;
    _pointView = [[UIView alloc]init];
    _pointView.layer.cornerRadius = 3;
    _pointView.layer.masksToBounds = YES;
    [self.contentView addSubview:_pointView];
    [_pointView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(6);
        make.centerY.mas_offset(0);
        make.left.mas_offset(15);
    }];
    
    
    
    _titleLab = [[QMUILabel alloc] init];
    [_titleLab setTextAlignment:NSTextAlignmentLeft];
    _titleLab.numberOfLines = 2;
    _titleLab.adjustsFontSizeToFitWidth = YES;
    _titleLab.minimumScaleFactor = 0.8;
    [_titleLab setFont:kBOLDSYSTEMFONT(14)];
    [_titleLab setTextColor:FontColor(@"#3F4443")];
    [self.contentView addSubview:_titleLab];
  
    
    _devIdLab = [[QMUILabel alloc] init];
    [_devIdLab setTextAlignment:NSTextAlignmentCenter];
    [_devIdLab setFont:kSYSTEMFONT(14)];
    [_devIdLab setTextColor:FontColor(@"#3F4443")];
    [self.contentView addSubview:_devIdLab];

    
    _markView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"agree"]];
    [_markView setBackgroundColor:UIColor.clearColor];
    [self.contentView addSubview:_markView];
  
  
    
    
    [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.pointView.mas_right).offset(3);
        make.centerY.mas_offset(0);
    }];
    
    
    
    [_devIdLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleLab.mas_right).offset(35);
        make.right.equalTo(weakSelf.markView.mas_left).offset(-35);
        make.centerY.mas_offset(0);
        make.width.offset(120);
    }];
    
    [_markView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.right.mas_offset(-22);
        make.centerY.mas_offset(0);
    }];
    
}


- (void)setEndPointModel:(RHLocalEndpointModel *)endPointModel{
    _endPointModel = endPointModel;
    [_devIdLab setText:endPointModel.sn];
    CGFloat width = [endPointModel.sn getStringWidthFont:_devIdLab.font limitHeight:20];
    [_devIdLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.offset(width+2);
    }];
    
    if(endPointModel.state == 1){//在线
        _pointView.backgroundColor = CMainColorGreen;
        _titleLab.textColor = CMainColorGreen;
    }else if (endPointModel.state == 2){//失联
        _pointView.backgroundColor = kCOLOR_HEX(@"BBBBBB");
        _titleLab.textColor = kCOLOR_HEX(@"BBBBBB");
    }
}


- (void)setIsSelect:(BOOL)isSelect{
    _isSelect = isSelect;
    _markView.hidden = !isSelect;
}

@end
